home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Software Contest 3
/
FM Towns Software Contest 3.iso
/
exp
/
astral
/
a1
/
game
/
source
/
wire3d_c.c
< prev
Wrap
C/C++ Source or Header
|
1994-01-07
|
3KB
|
150 lines
// "wire3d_c.c"
// ワイヤーフレームによる物体の表現(C言語版)
#include "wire3d.h"
#include <stdio.h>
#include "sin8.c"
void wire3d(ANGLE *angle,int *offset,WIRE_OBJECT *obj,int page)
{
int i;
int point_num_m3,point_work[MAX_POINT*3];
int line_num_m2;
int x1,y1,x2,y2,w,xx,yy;
int point_w[4][3],z_w,pass[MAX_POINT*3];
// 回転,オフセット付加,透視変換
point_num_m3=obj->point_num*3;
for(i=0;i<point_num_m3;i+=3){
// Y軸の回転
point_w[1][0]=( obj->point[i+0] * cos_data[angle[1]] -
obj->point[i+2] * sin_data[angle[1]] )>>7;
point_w[1][2]=( obj->point[i+0] * sin_data[angle[1]] +
obj->point[i+2] * cos_data[angle[1]] )>>7;
// X軸の回転
point_w[2][1]=( obj->point[i+1] * cos_data[angle[0]] +
point_w[1][2] * sin_data[angle[0]])>>7;
point_w[3][2]=((-obj->point[i+1] * sin_data[angle[0]] +
point_w[1][2] * cos_data[angle[0]])>>7)+offset[2];
// Z軸の回転
point_w[3][0]=(( point_w[1][0] * cos_data[angle[2]] +
point_w[2][1] * sin_data[angle[2]])>>7)+offset[0];
point_w[3][1]=((-point_w[1][0] * sin_data[angle[2]] +
point_w[2][1] * cos_data[angle[2]])>>7)+offset[1];
// 透視変換
pass[i]=0;
z_w=point_w[3][2]+0x100;
if(z_w<=0){
pass[i]=1;
continue;
}
point_work[i+0]=(( point_w[3][0]<<8)/z_w)+128;
point_work[i+1]=((-point_w[3][1]<<8)/z_w)+120;
}
// クリッピング,描画
line_num_m2=obj->line_num*2;
for(i=0;i<line_num_m2;i+=2){
if(pass[obj->line[i]*3]==1 || pass[obj->line[i+1]*3]==1)continue;
x1=point_work[obj->line[i ]*3 ];
y1=point_work[obj->line[i ]*3+1];
x2=point_work[obj->line[i+1]*3 ];
y2=point_work[obj->line[i+1]*3+1];
if(x1>0 && x1<255 && y1>0 && y1<255 &&
x2>0 && x2<255 && y2>0 && y2<255){
line(x1,y1,x2,y2,obj->color,page);
continue;
}
if( (x1<0 && x2<0) || (x1>255 && x2>255) ||
(y1<0 && y2<0) || (y1>255 && y2>255) ){
continue;
}
if(x2<0){
xx=1;
}
else{
if(x2>255){
xx=255;
}
else{
xx=x2;
}
}
if(x2==x1){
yy=y2;
}
else{
yy=y2-(y2-y1)*(x2-xx)/(x2-x1);
}
if(yy<0){
yy=0;
}
else{
if(yy>255){
yy=255;
}
else{
goto EXIT1;
}
}
if(y2==y1){
xx=x2;
}
else{
xx=x2-(x2-x1)*(y2-yy)/(y2-y1);
}
EXIT1:
x2=xx;
y2=yy;
w=x2;x2=x1;x1=w;
w=y2;y2=y1;y1=w;
if(x2<0){
xx=1;
}
else{
if(x2>255){
xx=255;
}
else{
xx=x2;
}
}
if(x2==x1){
yy=y2;
}
else{
yy=y2-(y2-y1)*(x2-xx)/(x2-x1);
}
if(yy<0){
yy=0;
}
else{
if(yy>255){
yy=255;
}
else{
goto EXIT2;
}
}
if(y2==y1){
xx=x2;
}
else{
xx=x2-(x2-x1)*(y2-yy)/(y2-y1);
}
EXIT2:
x2=xx;
y2=yy;
line(x1,y1,x2,y2,obj->color,page);
}
}